package com.yuncheng.spcyApi.busService;

import cn.hutool.core.date.DateUtil;
import com.yuncheng.entity.YcSysUser;
import com.yuncheng.vo.CurrentUserVo;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuncheng.spcyApi.constant.common.SpcyConstant;
import com.yuncheng.spcyApi.constant.flow.*;
import com.yuncheng.spcyApi.entity.*;
import com.yuncheng.spcyApi.flow.SpcyFlowConstant;
import com.yuncheng.spcyApi.flowService.QycjsqFlowService;
import com.yuncheng.spcyApi.flowService.SpzgqrFlowService;
import com.yuncheng.spcyApi.mapper.*;
import com.yuncheng.spcyApi.service.*;
import com.yuncheng.spcyApi.vo.common.NodeTjVo;
import com.yuncheng.spcyApi.vo.common.OrderItemVo;
import com.yuncheng.spcyApi.vo.common.StartEndTimeVo;
import com.yuncheng.spcyApi.vo.flow.YbjcyFlowVo;
import com.yuncheng.spcyApi.vo.flow.ZltxwjFlowListVo;
import com.yuncheng.spcyApi.vo.jcy.DpxxVo;
import com.yuncheng.spcyApi.vo.ndkp.KhxxVo;
import com.yuncheng.spcyApi.vo.ndkp.NdkpFlowVo;
import com.yuncheng.spcyApi.vo.spcy.SpcyFlowVo;
import com.yuncheng.spcyApi.vo.sqsx.MyXpjlVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import utils.DateConversionUtils;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;

@Component(value = "myJbxxService")
public class MyJbxxService {
    private static final Logger log = LoggerFactory.getLogger(MyJbxxService.class);

    @Resource
    @Lazy
    private IYcSysUserService ycSysUserService;

    @Resource
    @Lazy
    private ISpcyRsHcyService spcyRsHcyService;

    @Resource
    @Lazy
    private SpcySqsxXpjlMapper spcySqsxXpjlMapper;

    @Resource
    @Lazy
    private ISpcySqsxBaiscService spcySqsxBaiscService;

    @Resource
    @Lazy
    private ISpcyKpNdkpBasicService spcyKpNdkpBasicService;

    @Resource
    @Lazy
    private ISpcySqsxWjjlService spcySqsxWjjlService;

    @Resource
    @Lazy
    private SpcyFlowMapper spcyFlowMapper;

    @Resource
    @Lazy
    private SpcyKpYbjcyMapper spcyKpYbjcyMapper;

    @Resource
    @Lazy
    private SpcyKpNdkpBasicMapper spcyKpNdkpBasicMapper;

    @Resource
    @Lazy
    private ISpcyRsMhpzService spcyRsMhpzService;

    @Resource
    @Lazy
    private SpBzFlowConstant spBzFlowConstant;

    @Resource
    @Lazy
    private SpcyZjFlowConstant spcyZjFlowConstant;

    @Resource
    @Lazy
    private JsscbgFlowConstant jsscbgFlowConstant;

    @Resource
    @Lazy
    private SpzgqrFlowService spzgqrFlowService;

    @Resource
    @Lazy
    private QycjsqFlowService qycjsqFlowService;

    @Resource
    @Lazy
    private ZltxwjFlowConstant zltxwjFlowConstant;

    @Resource
    @Lazy
    private SpcyZltxwjFlowMapper spcyZltxwjFlowMapper;


    /**
     * 我的基本信息
     * @param userid
     * @return
     */
    public Map queryMyJbxx(String userid){
        Map map = new HashMap();

        YcSysUser user = ycSysUserService.getById(userid);
        map.put("user",user);

        /******************************** 【      检 查 员    】  *********************************************************** */

        List<SpcyRsHcy> hcyList = spcyRsHcyService.list(new LambdaQueryWrapper<SpcyRsHcy>()
                .eq(SpcyRsHcy::getFuserid, userid)
                .eq(SpcyRsHcy::getFusertype, SpcyConstant.HCY_USERTYPE_JCY));

        SpcyRsHcy ypscHcy = null; // 药品生产-核查员
        SpcyRsHcy ypzcHcy = null; // 药品注册-核查员
        SpcyRsHcy ypltHcy = null; // 药品流通-核查员
        SpcyRsHcy ylqxHcy = null; // 医疗器械-核查员
        SpcyRsHcy hzpHcy = null;  // 化妆品-核查员
        if (CollectionUtils.isNotEmpty(hcyList)){
            // 药品生产
            List<SpcyRsHcy> ypscHcyList = hcyList.stream().filter(x -> StringUtils.isNotBlank(x.getFywflcode()) && x.getFywflcode().equals(SpcyConstant.YWFL_CODE_YPSC))
                    .collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(ypscHcyList)){
                ypscHcy = ypscHcyList.get(0);
            }

            // 药品注册
            List<SpcyRsHcy> ypzcHcyList = hcyList.stream().filter(x -> StringUtils.isNotBlank(x.getFywflcode()) && x.getFywflcode().equals(SpcyConstant.YWFL_CODE_YPZC))
                    .collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(ypzcHcyList)){
                ypzcHcy = ypzcHcyList.get(0);
            }

            // 药品流通
            List<SpcyRsHcy> ypltHcyList = hcyList.stream().filter(x -> StringUtils.isNotBlank(x.getFywflcode()) && x.getFywflcode().equals(SpcyConstant.YWFL_CODE_YPJY))
                    .collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(ypltHcyList)){
                ypltHcy = ypltHcyList.get(0);
            }

            // 医疗器械
            List<SpcyRsHcy> ylqxHcyList = hcyList.stream().filter(x -> StringUtils.isNotBlank(x.getFywflcode()) && x.getFywflcode().equals(SpcyConstant.YWFL_CODE_YLQX))
                    .collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(ylqxHcyList)){
                ylqxHcy = ylqxHcyList.get(0);
            }

            // 化妆品
            List<SpcyRsHcy> hzpHcyList = hcyList.stream().filter(x -> StringUtils.isNotBlank(x.getFywflcode()) && x.getFywflcode().equals(SpcyConstant.YWFL_CODE_HZP))
                    .collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(hzpHcyList)){
                hzpHcy = hzpHcyList.get(0);
            }

        }
        map.put("ypscHcy",ypscHcy);
        map.put("ypzcHcy",ypzcHcy);
        map.put("ypltHcy",ypltHcy);
        map.put("ylqxHcy",ylqxHcy);
        map.put("hzpHcy",hzpHcy);

        /******************************** 【      专 家    】  *********************************************************** */
        List<SpcyRsHcy> zjHcyList = spcyRsHcyService.list(new LambdaQueryWrapper<SpcyRsHcy>()
                .eq(SpcyRsHcy::getFuserid, userid)
                .eq(SpcyRsHcy::getFusertype, SpcyConstant.HCY_USERTYPE_ZJ));

        SpcyRsHcy ypscZj = null; // 药品生产-专家
        SpcyRsHcy ypzcZj = null; // 药品注册-专家
        SpcyRsHcy ypltZj = null; // 药品流通-专家
        SpcyRsHcy ylqxZj = null; // 医疗器械-专家
        SpcyRsHcy hzpZj = null;  // 化妆品-专家
        if (CollectionUtils.isNotEmpty(zjHcyList)){
            // 药品生产
            List<SpcyRsHcy> ypscHcyList = zjHcyList.stream().filter(x -> StringUtils.isNotBlank(x.getFywflcode()) && x.getFywflcode().equals(SpcyConstant.YWFL_CODE_YPSC))
                    .collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(ypscHcyList)){
                ypscZj = ypscHcyList.get(0);
            }

            // 药品注册
            List<SpcyRsHcy> ypzcHcyList = zjHcyList.stream().filter(x -> StringUtils.isNotBlank(x.getFywflcode()) && x.getFywflcode().equals(SpcyConstant.YWFL_CODE_YPZC))
                    .collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(ypzcHcyList)){
                ypzcZj = ypzcHcyList.get(0);
            }

            // 药品流通
            List<SpcyRsHcy> ypltHcyList = zjHcyList.stream().filter(x -> StringUtils.isNotBlank(x.getFywflcode()) && x.getFywflcode().equals(SpcyConstant.YWFL_CODE_YPJY))
                    .collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(ypltHcyList)){
                ypltZj = ypltHcyList.get(0);
            }

            // 医疗器械
            List<SpcyRsHcy> ylqxHcyList = zjHcyList.stream().filter(x -> StringUtils.isNotBlank(x.getFywflcode()) && x.getFywflcode().equals(SpcyConstant.YWFL_CODE_YLQX))
                    .collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(ylqxHcyList)){
                ylqxZj = ylqxHcyList.get(0);
            }

            // 化妆品
            List<SpcyRsHcy> hzpHcyList = zjHcyList.stream().filter(x -> StringUtils.isNotBlank(x.getFywflcode()) && x.getFywflcode().equals(SpcyConstant.YWFL_CODE_HZP))
                    .collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(hzpHcyList)){
                hzpZj = hzpHcyList.get(0);
            }
        }
        map.put("ypscZj",ypscZj);
        map.put("ypzcZj",ypzcZj);
        map.put("ypltZj",ypltZj);
        map.put("ylqxZj",ylqxZj);
        map.put("hzpZj",hzpZj);

        /******************************** 【      评 审 员  】  ****************************************************** */
        List<SpcyRsHcy> psyHcyList = spcyRsHcyService.list(new LambdaQueryWrapper<SpcyRsHcy>()
                .eq(SpcyRsHcy::getFuserid, userid)
                .eq(SpcyRsHcy::getFusertype, SpcyConstant.HCY_USERTYPE_PSY));

        SpcyRsHcy ypscPsy = null; // 药品生产-评审员
        SpcyRsHcy ypzcPsy = null; // 药品注册-评审员
        SpcyRsHcy ypltPsy = null; // 药品流通-评审员
        SpcyRsHcy ylqxPsy = null; // 医疗器械-评审员
        SpcyRsHcy hzpPsy = null; // 化妆品-评审员

        /*if (CollectionUtils.isNotEmpty(psyHcyList)){
            // 药品生产
            List<SpcyRsHcy> ypscHcyList = psyHcyList.stream().filter(x -> StringUtils.isNotBlank(x.getFywflcode())
                    && x.getFywflcode().equals("psy001002"))
                    .collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(ypscHcyList)){
                ypscPsy = ypscHcyList.get(0);
            }

            // 药品注册
            List<SpcyRsHcy> ypzcHcyList = psyHcyList.stream().filter(x -> StringUtils.isNotBlank(x.getFywflcode())
                    && x.getFywflcode().equals("psy001001"))
                    .collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(ypzcHcyList)){
                ypzcPsy = ypzcHcyList.get(0);
            }

            // 药品流通
            List<SpcyRsHcy> ypltHcyList = psyHcyList.stream().filter(x -> StringUtils.isNotBlank(x.getFywflcode())
                    && x.getFywflcode().equals("psy001003"))
                    .collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(ypltHcyList)){
                ypltPsy = ypltHcyList.get(0);
            }

            // 医疗器械
            List<SpcyRsHcy> ylqxHcyList = psyHcyList.stream().filter(x -> StringUtils.isNotBlank(x.getFywflcode())
                    && x.getFywflcode().equals("psy002"))
                    .collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(ylqxHcyList)){
                ylqxPsy = ylqxHcyList.get(0);
            }

            // 化妆品
            List<SpcyRsHcy> hzpHcyList = psyHcyList.stream().filter(x -> StringUtils.isNotBlank(x.getFywflcode())
                    && x.getFywflcode().equals("psy003"))
                    .collect(Collectors.toList());
            if (CollectionUtils.isNotEmpty(hzpHcyList)){
                hzpPsy = hzpHcyList.get(0);
            }
        }*/
        map.put("ypscPsy",ypscPsy);
        map.put("ypzcPsy",ypzcPsy);
        map.put("ypltPsy",ypltPsy);
        map.put("ylqxPsy",ylqxPsy);
        map.put("hzpPsy",hzpPsy);

        return map;
    }

    /**
     * 获取我的选派记录
     * @param myXpjlVo
     * @param pageNo
     * @param pageSize
     * @return
     */
    public IPage<MyXpjlVo> queryMyXpjl(MyXpjlVo myXpjlVo, Integer pageNo, Integer pageSize){
        Page<MyXpjlVo> page = new Page<>(pageNo,pageSize);
        if (StringUtils.isNotBlank(myXpjlVo.getId())){
            myXpjlVo.setId("");
        }
        IPage<MyXpjlVo> xpjlPageList = spcySqsxXpjlMapper.getXpjlPageList(page, myXpjlVo);

        return xpjlPageList;
    }

    public List<MyXpjlVo> queryMyXpjlList(MyXpjlVo myXpjlVo){
        List<MyXpjlVo> xpjlPageList = spcySqsxXpjlMapper.getXpjlList(myXpjlVo);

        return xpjlPageList;
    }

    /**
     * 获取我的考核信息
     * @param year
     * @param userid
     * @return
     */
    public List<KhxxVo> queryMyKhxx(String year, String userid){
        List<KhxxVo> khxxVoList = new ArrayList<>();
        KhxxVo khxxVo = null;

        // 日常考核
        MyXpjlVo myXpjlVo = new MyXpjlVo();
        myXpjlVo.setFuserid(userid);
        myXpjlVo.setYear(year);

        List<MyXpjlVo> xpjlPageList = spcySqsxXpjlMapper.getXpjlList(myXpjlVo);

        if (CollectionUtils.isNotEmpty(xpjlPageList)){
            for (MyXpjlVo xpjlVo : xpjlPageList){
                khxxVo = new KhxxVo();
                khxxVo.setFuserid(xpjlVo.getFuserid());
                khxxVo.setFjcyid(xpjlVo.getFjcyid());
                khxxVo.setFjcyxm(xpjlVo.getFjcyxm());
                khxxVo.setFkhlx(SpcyConstant.KHLX_RCKH); // 日常考核
                khxxVo.setFkhjg(xpjlVo.getFzhpj());
                khxxVo.setFbz(xpjlVo.getFbz());
                khxxVo.setFkhsj(xpjlVo.getFrckpsj());
                khxxVoList.add(khxxVo);
            }
        }

        // 年度考核
        List<SpcyKpNdkpBasic> ndkpList = spcyKpNdkpBasicService.list(new LambdaQueryWrapper<SpcyKpNdkpBasic>()
                .eq(SpcyKpNdkpBasic::getFuserid, userid)
                .eq(StringUtils.isNotBlank(year),SpcyKpNdkpBasic::getFyear,year));
        if (CollectionUtils.isNotEmpty(ndkpList)){
            for (SpcyKpNdkpBasic ndkp : ndkpList){
                khxxVo = new KhxxVo();
                khxxVo.setFuserid(ndkp.getFuserid());

                List<SpcyRsHcy> hcyList = spcyRsHcyService.list(new LambdaQueryWrapper<SpcyRsHcy>()
                        .eq(SpcyRsHcy::getFuserid, userid)
                        .eq(StringUtils.isNotBlank(ndkp.getFywflcode()),SpcyRsHcy::getFywflcode, ndkp.getFywflcode()));
                if (CollectionUtils.isNotEmpty(hcyList)) {
                    khxxVo.setFjcyid(hcyList.get(0).getId());
                }

                khxxVo.setFjcyxm(ndkp.getFusermc());
                khxxVo.setFkhlx(SpcyConstant.KHLX_NDKH); // 年度考核
                khxxVo.setFkhjg(ndkp.getFndzhkpjg());
                khxxVo.setFbz(ndkp.getFbz());
                khxxVo.setFkhsj(ndkp.getFndkpsj());

                khxxVoList.add(khxxVo);
            }
        }

        return khxxVoList;
    }

    /**
     * 获取我的调派信息
     * @param year
     * @param userid
     * @param name
     * @return
     */
    public List<DpxxVo> queryMyDpxx(String year, String userid, String name){
        List<DpxxVo> dpxxVoList = new ArrayList<>();
        MyXpjlVo myXpjlVo = new MyXpjlVo();
        myXpjlVo.setFuserid(userid);
        myXpjlVo.setYear(year);

        List<MyXpjlVo> xpjlPageList = spcySqsxXpjlMapper.getXpjlList(myXpjlVo);
        String dpcs = String.valueOf(xpjlPageList.size()); // 调派次数
        String jsdpcs = "0"; // 接受调派
        String wjsdpcs = "0"; // 不接受调派

        if (CollectionUtils.isNotEmpty(xpjlPageList)){
            List<MyXpjlVo> jsdpcsList = xpjlPageList.stream().filter(
                    x -> StringUtils.isNotBlank(x.getFsftyxp()) && StringUtils.isNotBlank(x.getFspcylx())
                            && x.getFsftyxp().equals(SpcyConstant.XPJL_SFTYXP_YES)
                            && x.getFspcylx().equals(SpcyConstant.FLOW_TYPE_CY)).collect(Collectors.toList());
            jsdpcs = String.valueOf(jsdpcsList.size());

            List<MyXpjlVo> wjsdpcsList = xpjlPageList.stream().filter(
                    x -> StringUtils.isNotBlank(x.getFsftyxp()) && StringUtils.isNotBlank(x.getFspcylx())
                            && x.getFsftyxp().equals(SpcyConstant.XPJL_SFTYXP_NO)
                            && x.getFspcylx().equals(SpcyConstant.FLOW_TYPE_CY)).collect(Collectors.toList());
            wjsdpcs = String.valueOf(wjsdpcsList.size());
        }

        // 获取当前用户的总选派次数 (查验)
        List<SpcySqsxXpjl> totalCountList = spcySqsxXpjlMapper.selectList(new LambdaQueryWrapper<SpcySqsxXpjl>()
                .eq(SpcySqsxXpjl::getFuserid, userid)
                .eq(SpcySqsxXpjl::getFspcylx,SpcyConstant.FLOW_TYPE_CY));
        String totalcs = String.valueOf(totalCountList.size()); // 总选派次数
        String totaltycs = "0"; // 总同意次数
        String totalbtycs = "0"; // 总不同意次数
        if (CollectionUtils.isNotEmpty(totalCountList)){
            List<SpcySqsxXpjl> totaltycsList = totalCountList.stream().filter(x -> StringUtils.isNotBlank(x.getFsftyxp()) && StringUtils.isNotBlank(x.getFspcylx())
                    && x.getFsftyxp().equals(SpcyConstant.XPJL_SFTYXP_YES)
                    && x.getFspcylx().equals(SpcyConstant.FLOW_TYPE_CY)).collect(Collectors.toList());
            totaltycs = String.valueOf(totaltycsList.size());

            List<SpcySqsxXpjl> totalbtycsList = totalCountList.stream().filter(x -> StringUtils.isNotBlank(x.getFsftyxp()) && StringUtils.isNotBlank(x.getFspcylx())
                    && x.getFsftyxp().equals(SpcyConstant.XPJL_SFTYXP_NO)
                    && x.getFspcylx().equals(SpcyConstant.FLOW_TYPE_CY)).collect(Collectors.toList());
            totalbtycs = String.valueOf(totalbtycsList.size());
        }

        DpxxVo dpxxVo = new DpxxVo();
        dpxxVo.setDpcs(dpcs);
        dpxxVo.setYear(year);
        dpxxVo.setFuserid(userid);
        dpxxVo.setTotaldpcs(totalcs);
        dpxxVo.setTotaljsdpcs(totaltycs);
        dpxxVo.setTotalwjsdpcs(totalbtycs);
        if (CollectionUtils.isNotEmpty(xpjlPageList)) {
            dpxxVo.setFjcyid(xpjlPageList.get(0).getFjcyid());
        }
        dpxxVo.setFjcyxm(name);
        dpxxVo.setJsdpcs(jsdpcs);
        dpxxVo.setWjsdpcs(wjsdpcs);
        dpxxVoList.add(dpxxVo);

        return dpxxVoList;
    }

    /**
     * 按科室流程数据统计
     * @param startEndTimeVo
     * @param fywflcode
     * @return
     */
    public Map queryDeptFlowTjData(StartEndTimeVo startEndTimeVo, String fywflcode){
        Map map = new HashMap();

        String now = "";
        String today = "";
        String month = "";
        if (startEndTimeVo.getStartTime() != null){
            now = DateConversionUtils.DateToDays(startEndTimeVo.getStartTime());
            today = DateConversionUtils.DateToStringYYYYMMDD(startEndTimeVo.getStartTime());
            month = DateConversionUtils.DateToMonth(startEndTimeVo.getStartTime());
        }else {
            now = DateUtil.now();
            today = DateUtil.today();
            month = DateConversionUtils.DateToMonth(new Date());
        }

        /** 本月受理数 */
        // 受理时间不为空，受理时间等于当前日期
        List<SpcySqsxBasic> drslsList = spcySqsxBaiscService.list(new LambdaQueryWrapper<SpcySqsxBasic>()
                .eq(org.apache.commons.lang3.StringUtils.isNotBlank(fywflcode),SpcySqsxBasic::getFywflcode,fywflcode)
                .isNotNull(SpcySqsxBasic::getFslsj)
                .apply("to_char(fslsj,'yyyy-MM-dd') = {0}",today));
        int drsls = drslsList.size();
        map.put("drsls",drsls);

        /** 本月受理数 */
        // 受理时间不为空，受理时间等于当前月份
        List<SpcySqsxBasic> byslsList = spcySqsxBaiscService.list(new LambdaQueryWrapper<SpcySqsxBasic>()
                .eq(org.apache.commons.lang3.StringUtils.isNotBlank(fywflcode),SpcySqsxBasic::getFywflcode,fywflcode)
                .isNotNull(SpcySqsxBasic::getFslsj)
                .apply("to_char(fslsj,'yyyy-MM') = {0}",month));
        int bysls = byslsList.size();
        map.put("bysls",bysls);

        /** 当日完成数 */
        // 移送时间不为空，移送时间等于当前日期
        List<SpcySqsxBasic> drwcList = spcySqsxBaiscService.list(new LambdaQueryWrapper<SpcySqsxBasic>()
                .eq(org.apache.commons.lang3.StringUtils.isNotBlank(fywflcode),SpcySqsxBasic::getFywflcode,fywflcode)
                .isNotNull(SpcySqsxBasic::getFyssj)
                .apply("to_char(fyssj,'yyyy-MM-dd') = {0}",today));
        int drwc = drwcList.size();
        map.put("drwc",drwc);

        /** 本月完成数 */
        // 移送时间不为空，移送时间等于当前月份
        List<SpcySqsxBasic> bywcList = spcySqsxBaiscService.list(new LambdaQueryWrapper<SpcySqsxBasic>()
                .eq(org.apache.commons.lang3.StringUtils.isNotBlank(fywflcode),SpcySqsxBasic::getFywflcode,fywflcode)
                .isNotNull(SpcySqsxBasic::getFyssj)
                .apply("to_char(fyssj,'yyyy-MM') = {0}",month));
        int bywc = bywcList.size();
        map.put("bywc",bywc);

        /** 超期数 */
        // 截止日期不为空，移送时间不为空，移送时间小于等于截止日期 或 (截止日期不为空，移送时间为空，截止日期小于当前日期)
        List<SpcySqsxBasic> cqsList = spcySqsxBaiscService.list(new LambdaQueryWrapper<SpcySqsxBasic>()
                .eq(org.apache.commons.lang3.StringUtils.isNotBlank(fywflcode),SpcySqsxBasic::getFywflcode,fywflcode)
                .isNotNull(SpcySqsxBasic::getFyssj)
                .isNotNull(SpcySqsxBasic::getFjzrq)
                .apply("fyssj <= fjzrq")
                .or()
                .eq(StringUtils.isNotBlank(fywflcode),SpcySqsxBasic::getFywflcode,fywflcode)
                .isNotNull(SpcySqsxBasic::getFjzrq)
                .isNull(SpcySqsxBasic::getFyssj)
                .apply("to_char(fjzrq,'yyyy-mm-dd hh24:mi:ss') < {0}",now));
        int cqs = cqsList.size();
        map.put("cqs",cqs);

        /** 办理中 */
        // 移送时间为空，截止日期大于等于当前日期,
        List<SpcySqsxBasic> blzList = spcySqsxBaiscService.list(new LambdaQueryWrapper<SpcySqsxBasic>()
                .eq(org.apache.commons.lang3.StringUtils.isNotBlank(fywflcode),SpcySqsxBasic::getFywflcode,fywflcode)
                .isNotNull(SpcySqsxBasic::getFslsj)
                .isNull(SpcySqsxBasic::getFyssj)
                .apply("to_char(fjzrq,'yyyy-mm-dd hh24:mi:ss') >= {0}",now));

        int blz = blzList.size();
        map.put("blz",blz);

        return map;
    }

    /**
     * 审评查验 - 个人统计
     * // 审评查验流程
     * @param onlyCurrentUser 是否查询个人（true/查询、false/不查询）
     */
    public Map queryMyFlowTjData(boolean onlyCurrentUser,CurrentUserVo user){
        Map map = new HashMap();

        // 查询审评查验列表
        SpcyFlowVo FlowVo = new SpcyFlowVo();
        FlowVo.setFlcmc(YpscFlowConstant.LCMC_LIKE_SPCYLC); // 审评查验流程
        List<SpcyFlowVo> spcyFlowList = spcyFlowMapper.flowJkList(onlyCurrentUser,user,FlowVo);

        // 查询待办列表
        /*SpcyFlowVo dbFlowVo = new SpcyFlowVo();
        dbFlowVo.setFblzt(SpcyConstant.BLZT_DB);
        dbFlowVo.setFlcmc(YpscFlowConstant.LCMC_LIKE_SPCYLC); // 审评查验流程
        List<SpcyFlowVo> dbSpcyFlowList = spcyFlowMapper.flowJkList(onlyCurrentUser,user,dbFlowVo);*/

        Integer ljybsl = 0; // 累计已办数量
        Integer ljybcqs = 0; // 累计超期已办理数

        Integer bydbbls = 0; // 本月待办理数
        Integer bydbcqs = 0; // 本月超期待办理数
        Date nowDate = new Date(); // 当前日期

        if (CollectionUtils.isNotEmpty(spcyFlowList)){
            int yearByDate = DateConversionUtils.getYearByDate(nowDate); // 年份
            int monthByDate = DateConversionUtils.getMonthByDate(nowDate);// 月份

            // 获取本月待办理数
            List<SpcyFlowVo> byblList = spcyFlowList.stream()
                    .filter(f -> f.getFfssj() != null
                            && DateConversionUtils.getYearByDate(f.getFfssj()) == yearByDate
                            && DateConversionUtils.getMonthByDate(f.getFfssj()) == monthByDate
                            && StringUtils.isNotBlank(f.getFblzt())
                            && (f.getFblzt().equals(SpcyConstant.BLZT_TH) || f.getFblzt().equals(SpcyConstant.BLZT_DB))
                    )
                    .collect(
                            Collectors.collectingAndThen(
                                    Collectors.toCollection(
                                            () -> new TreeSet<>(
                                                    Comparator.comparing(o -> o.getSqsxid())
                                            )
                                    ), ArrayList<SpcyFlowVo>::new
                            )
                    );
            bydbbls = byblList.size();

            // 获取本月超期待办理数
            if (CollectionUtils.isNotEmpty(byblList)){
                // (累计超期数) 截止日期、移送时间
                List<SpcyFlowVo> cqblList = byblList.stream()
                        .filter(f ->
                                ((f.getFjzrq() != null
                                        && f.getFyssj() != null
                                        && f.getFyssj().compareTo(f.getFjzrq()) > 0
                                ) || (
                                        f.getFjzrq() != null
                                        && f.getFyssj() == null
                                        && nowDate.compareTo(f.getFjzrq()) > 0
                                ))
                        )
                        .collect(
                                Collectors.collectingAndThen(
                                        Collectors.toCollection(
                                                () -> new TreeSet<>(
                                                        Comparator.comparing(o -> o.getSqsxid())
                                                )
                                        ), ArrayList<SpcyFlowVo>::new
                                )
                        );
                bydbcqs = cqblList.size();
            }
        }

        if (CollectionUtils.isNotEmpty(spcyFlowList)){
            // 累计已办数量
            ljybsl = spcyFlowList.stream()
                    .filter(f -> StringUtils.isNotBlank(f.getFblzt())
                            && f.getFblzt().equals(SpcyConstant.BLZT_YB)
                    )
                    .collect(
                            Collectors.collectingAndThen(
                                    Collectors.toCollection(
                                            () -> new TreeSet<>(
                                                    Comparator.comparing(o -> o.getSqsxid())
                                            )
                                    ), ArrayList<SpcyFlowVo>::new
                            )
                    ).size();

            // (累计超期数) 截止日期、移送时间
            ljybcqs = spcyFlowList.stream()
                    .filter(f -> StringUtils.isNotBlank(f.getFblzt())
                            && f.getFblzt().equals(SpcyConstant.BLZT_YB)
                            && ((f.getFjzrq() != null
                                    && f.getFyssj() != null
                                    && f.getFyssj().compareTo(f.getFjzrq()) > 0
                            )
                            || (f.getFjzrq() != null
                                    && f.getFyssj() == null
                                    && nowDate.compareTo(f.getFjzrq()) > 0
                            ))
                    )
                    .collect(
                            Collectors.collectingAndThen(
                                    Collectors.toCollection(
                                            () -> new TreeSet<>(
                                                    Comparator.comparing(o -> o.getSqsxid())
                                            )
                                    ), ArrayList<SpcyFlowVo>::new
                            )
                    )
                    .size();
        }

        map.put("ljybsl",ljybsl); // 累计已办理数
        map.put("ljybcqs",ljybcqs); // 累计超期已办理数
        map.put("bydbbls",bydbbls); // 本月待办理数
        map.put("bydbcqs",bydbcqs); // 本月超期待办理数

        return map;
    }

    /**
     * 行政审批-系统调用-我的待办数量
     * // 审评查验、补正、专家、技术审查报告等流程
     */
    public long mySpcyFlowNum(String userid){
        long num = 0;

        Page<SpcySqsxJob> page = new Page<>(1, 10);
        num = spcyFlowMapper.selectCommonFlowList(page, userid, null, SpcyFlowConstant.LCMC_LIKE_SPCYLC, SpcyConstant.BLZT_DB)
                .getTotal();

        return num;
    }

    /**
     * 通过用户账号-获取用户信息
     */
    public YcSysUser getNowUserByLoginName(String loginName){

        List<YcSysUser> sysUserList = ycSysUserService.list(new LambdaQueryWrapper<YcSysUser>()
                .eq(YcSysUser::getUsername, loginName));

        if (CollectionUtils.isNotEmpty(sysUserList)){
            return sysUserList.get(0);
        }

        return null;
    }

    /**
     * 获取当前用户 - 角色 - 门户首页页面
     */
    public String queryNowUserRoleMhpz(){
        String url = "";
        List<SpcyRsMhpz> mhList = spcyRsMhpzService.list(new LambdaQueryWrapper<SpcyRsMhpz>()
                .orderByAsc(SpcyRsMhpz::getCreateTime));
        if (CollectionUtils.isNotEmpty(mhList)){
            url = mhList.get(0).getFlj();
        }

        return url;
    }

    /**
     * 审评查验 - 药品注册 - 我的待办
     * @param onlyCurrentUser 查询当前用户
     * @param user 当前用户
     */
    public Map mySpcyByYpzcDb(Page<SpcyFlowVo> page,boolean onlyCurrentUser,CurrentUserVo user){
        Map resultMap = new HashMap();
        Map map = new HashMap();
        Date nowDate = new Date();

        SpcyFlowVo ypzcFlowVo = new SpcyFlowVo();
        ypzcFlowVo.setFywflcode(SpcyConstant.YWFL_CODE_YPZC);
        ypzcFlowVo.setFblzt(SpcyConstant.BLZT_DB);
        ypzcFlowVo.setFlcmc(SpcyConstant.getFlowConstant(SpcyConstant.YWFL_CODE_YPZC).getFlowName());
        List<SpcyFlowVo> spcyFlowList = spcyFlowMapper.flowJkList(onlyCurrentUser,user,ypzcFlowVo);

        map.put("dbList",spcyFlowList); // 待办数据列表

        // 超期待办数据
        List<SpcyFlowVo> cqDbFlowList = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(spcyFlowList)){
            cqDbFlowList = spcyFlowList.stream()
                    .filter(f ->
                            ((f.getFjzrq() != null
                                    && f.getFyssj() != null
                                    && f.getFyssj().compareTo(f.getFjzrq()) > 0
                            ) || (
                                    f.getFjzrq() != null
                                            && f.getFyssj() == null
                                            && nowDate.compareTo(f.getFjzrq()) > 0
                            ))
                    ).collect(Collectors.toList());
        }
        map.put("dbCqList",cqDbFlowList); // 超期待办列表

        Map<String, Long> ypzcSpcyFlowVo = new HashMap<>();
        if (CollectionUtils.isNotEmpty(spcyFlowList)){
            ypzcSpcyFlowVo = spcyFlowList.stream().collect(Collectors.groupingBy(
                    SpcyFlowVo::getFhjmc, Collectors.counting()
            ));
        }
        List<NodeTjVo> tjMap = ypzcSpcyFlowVo.entrySet().stream().map(e -> new NodeTjVo(e.getKey(), e.getValue())).collect(Collectors.toList());
        map.put("nodeTj",tjMap);

        map.putAll(this.mySpcyBzlcDb(onlyCurrentUser, user, SpcyConstant.YWFL_CODE_YPZC)); // 补正流程

        map.putAll(this.mySpcyZjFlowDb(onlyCurrentUser, user, SpcyConstant.YWFL_CODE_YPZC)); // 专家流程

        map.putAll(this.mySpcyZgFlowDb(onlyCurrentUser, user, SpcyConstant.YWFL_CODE_YPZC)); // 整改流程

        resultMap.put("ypzc",map);
        return resultMap;
    }

    /**
     * 审评查验 - 药品生产 - 我的待办
     */
    public Map mySpcyByYpscDb(Page<SpcyFlowVo> page,boolean onlyCurrentUser,CurrentUserVo user){
        Map resultMap = new HashMap();
        Map map = new HashMap();
        Date nowDate = new Date(); // 当前日期
        SpcyFlowVo ypscFlowVo = new SpcyFlowVo();
        ypscFlowVo.setFywflcode(SpcyConstant.YWFL_CODE_YPSC);
        ypscFlowVo.setFblzt(SpcyConstant.BLZT_DB);
        ypscFlowVo.setFlcmc(SpcyConstant.getFlowConstant(SpcyConstant.YWFL_CODE_YPSC).getFlowName());
        List<SpcyFlowVo> ypscSpcyFlowList = spcyFlowMapper.flowJkList(onlyCurrentUser,user,ypscFlowVo);

        map.put("dbList",ypscSpcyFlowList); // 待办数据列表

        // 超期待办数据
        List<SpcyFlowVo> cqDbFlowList = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(ypscSpcyFlowList)){
            cqDbFlowList = ypscSpcyFlowList.stream()
                    .filter(f ->
                            ((f.getFjzrq() != null
                                    && f.getFyssj() != null
                                    && f.getFyssj().compareTo(f.getFjzrq()) > 0
                            ) || (
                                    f.getFjzrq() != null
                                            && f.getFyssj() == null
                                            && nowDate.compareTo(f.getFjzrq()) > 0
                            ))
                    ).collect(Collectors.toList());
        }
        map.put("dbCqList",cqDbFlowList); // 超期待办列表

        Map<String, Long> ypscSpcyFlowVo = new HashMap<>();
        if (CollectionUtils.isNotEmpty(ypscSpcyFlowList)){
            ypscSpcyFlowVo = ypscSpcyFlowList.stream().collect(Collectors.groupingBy(
                    SpcyFlowVo::getFhjmc, Collectors.counting()
            ));
        }
        List<NodeTjVo> tjMap = ypscSpcyFlowVo.entrySet().stream().map(e -> new NodeTjVo(e.getKey(), e.getValue())).collect(Collectors.toList());
        map.put("nodeTj",tjMap);

//        map.putAll(this.mySpcyZgFlowDb(onlyCurrentUser, user, SpcyConstant.YWFL_CODE_YPJY)); // 整改流程

        resultMap.put("ypsc",map);
        return resultMap;
    }

    /**
     * 审评查验 - 药品流通 - 我的待办
     */
    public Map mySpcyByYpltDb(Page<SpcyFlowVo> page,boolean onlyCurrentUser,CurrentUserVo user){
        Map resultMap = new HashMap();
        Map map = new HashMap();
        Date nowDate = new Date(); // 当前日期

        SpcyFlowVo ypltFlowVo = new SpcyFlowVo();
        ypltFlowVo.setFywflcode(SpcyConstant.YWFL_CODE_YPJY);
        ypltFlowVo.setFblzt(SpcyConstant.BLZT_DB);
        ypltFlowVo.setFlcmc(SpcyConstant.getFlowConstant(SpcyConstant.YWFL_CODE_YPJY).getFlowName());
        List<SpcyFlowVo> spcyFlowList = spcyFlowMapper.flowJkList(onlyCurrentUser,user,ypltFlowVo);

        map.put("dbList",spcyFlowList); // 待办数据

        // 超期待办数据
        List<SpcyFlowVo> cqDbFlowList = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(spcyFlowList)){
            cqDbFlowList = spcyFlowList.stream()
                    .filter(f ->
                            ((f.getFjzrq() != null
                                    && f.getFyssj() != null
                                    && f.getFyssj().compareTo(f.getFjzrq()) > 0
                            ) || (
                                    f.getFjzrq() != null
                                            && f.getFyssj() == null
                                            && nowDate.compareTo(f.getFjzrq()) > 0
                            ))
                    ).collect(Collectors.toList());
        }
        map.put("dbCqList",cqDbFlowList); // 超期待办列表

        Map<String, Long> ypltSpcyFlowVo = new HashMap<>();
        if (CollectionUtils.isNotEmpty(spcyFlowList)){
            ypltSpcyFlowVo = spcyFlowList.stream().collect(Collectors.groupingBy(
                    SpcyFlowVo::getFhjmc, Collectors.counting()
            ));
        }
        List<NodeTjVo> tjMap = ypltSpcyFlowVo.entrySet().stream().map(e -> new NodeTjVo(e.getKey(), e.getValue())).collect(Collectors.toList());
        map.put("nodeTj",tjMap);

        map.putAll(this.mySpcyJsscbgFlowDb(onlyCurrentUser,user)); // 技术审查报告-流程

        map.putAll(this.mySpcyZgFlowDb(onlyCurrentUser, user, SpcyConstant.YWFL_CODE_YPJY)); // 整改流程

        resultMap.put("yplt",map);
        return resultMap;
    }

    /**
     * 审评查验 - 医疗器械 - 我的待办
     */
    public Map mySpcyByYlqxDb(Page<SpcyFlowVo> page,boolean onlyCurrentUser,CurrentUserVo user){
        Map resultMap = new HashMap();
        Map map = new HashMap();
        Date nowDate = new Date(); // 当前日期

        SpcyFlowVo ylqxFlowVo = new SpcyFlowVo();
        ylqxFlowVo.setFywflcode(SpcyConstant.YWFL_CODE_YLQX);
        ylqxFlowVo.setFblzt(SpcyConstant.BLZT_DB);
        ylqxFlowVo.setFlcmc(SpcyConstant.getFlowConstant(SpcyConstant.YWFL_CODE_YLQX).getFlowName());
        List<SpcyFlowVo> spcyFlowList = spcyFlowMapper.flowJkList(onlyCurrentUser,user,ylqxFlowVo);

        map.put("dbList",spcyFlowList); // 待办数据

        // 超期待办数据
        List<SpcyFlowVo> cqDbFlowList = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(spcyFlowList)){
            cqDbFlowList = spcyFlowList.stream()
                    .filter(f ->
                            ((f.getFjzrq() != null
                                    && f.getFyssj() != null
                                    && f.getFyssj().compareTo(f.getFjzrq()) > 0
                            ) || (
                                    f.getFjzrq() != null
                                            && f.getFyssj() == null
                                            && nowDate.compareTo(f.getFjzrq()) > 0
                            ))
                    ).collect(Collectors.toList());
        }
        map.put("dbCqList",cqDbFlowList); // 超期待办列表

        Map<String, Long> ylqxSpcyFlowVo = new HashMap<>();
        if (CollectionUtils.isNotEmpty(spcyFlowList)){
            ylqxSpcyFlowVo = spcyFlowList.stream().collect(Collectors.groupingBy(
                    SpcyFlowVo::getFhjmc, Collectors.counting()
            ));
        }
        List<NodeTjVo> tjMap = ylqxSpcyFlowVo.entrySet().stream().map(e -> new NodeTjVo(e.getKey(), e.getValue())).collect(Collectors.toList());
        map.put("nodeTj",tjMap);

        map.putAll(this.mySpcyBzlcDb(onlyCurrentUser, user, SpcyConstant.YWFL_CODE_YLQX)); // 补正流程

        map.putAll(this.mySpcyZjFlowDb(onlyCurrentUser, user, SpcyConstant.YWFL_CODE_YLQX)); // 专家流程

//        map.putAll(this.mySpcyZgFlowDb(onlyCurrentUser, user, SpcyConstant.YWFL_CODE_YLQX)); // 整改流程

        resultMap.put("ylqx",map);
        return resultMap;
    }

    /**
     * 审评查验 - 化妆品 - 我的待办
     */
    public Map mySpcyByHzpDb(Page<SpcyFlowVo> page,boolean onlyCurrentUser,CurrentUserVo user){
        Map resultMap = new HashMap();
        Map map = new HashMap();
        Date nowDate = new Date(); // 当前日期

        SpcyFlowVo hzpFlowVo = new SpcyFlowVo();
        hzpFlowVo.setFywflcode(SpcyConstant.YWFL_CODE_HZP);
        hzpFlowVo.setFblzt(SpcyConstant.BLZT_DB);
        hzpFlowVo.setFlcmc(SpcyConstant.getFlowConstant(SpcyConstant.YWFL_CODE_HZP).getFlowName());
        List<SpcyFlowVo> spcyFlowList = spcyFlowMapper.flowJkList(onlyCurrentUser,user,hzpFlowVo);

        map.put("dbList",spcyFlowList); // 待办数据

        // 超期待办数据
        List<SpcyFlowVo> cqDbFlowList = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(spcyFlowList)){
            cqDbFlowList = spcyFlowList.stream()
                    .filter(f ->
                            ((f.getFjzrq() != null
                                    && f.getFyssj() != null
                                    && f.getFyssj().compareTo(f.getFjzrq()) > 0
                            ) || (
                                    f.getFjzrq() != null
                                            && f.getFyssj() == null
                                            && nowDate.compareTo(f.getFjzrq()) > 0
                            ))
                    ).collect(Collectors.toList());
        }
        map.put("dbCqList",cqDbFlowList); // 超期待办列表

        Map<String, Long> hzpSpcyFlowVo = new HashMap<>();
        if (CollectionUtils.isNotEmpty(spcyFlowList)){
            hzpSpcyFlowVo = spcyFlowList.stream().collect(Collectors.groupingBy(
                    SpcyFlowVo::getFhjmc, Collectors.counting()
            ));
        }
        List<NodeTjVo> tjMap = hzpSpcyFlowVo.entrySet().stream().map(e -> new NodeTjVo(e.getKey(), e.getValue())).collect(Collectors.toList());
        map.put("nodeTj",tjMap);

        map.putAll(this.mySpcyBzlcDb(onlyCurrentUser, user, SpcyConstant.YWFL_CODE_HZP)); // 补正流程

        map.putAll(this.mySpcyZjFlowDb(onlyCurrentUser, user, SpcyConstant.YWFL_CODE_HZP)); // 专家流程

        map.putAll(this.mySpcyZgFlowDb(onlyCurrentUser, user, SpcyConstant.YWFL_CODE_HZP)); // 整改流程

        resultMap.put("hzp",map);
        return resultMap;
    }

    /**
     * 补正流程 - 我的待办
     */
    public Map mySpcyBzlcDb(boolean onlyCurrentUser, CurrentUserVo user, String fywflcode){
        Map resultMap = new HashMap();

        SpcyFlowVo ylqxFlowVo = new SpcyFlowVo();
        ylqxFlowVo.setFywflcode(fywflcode);
        ylqxFlowVo.setFblzt(SpcyConstant.BLZT_DB);
        ylqxFlowVo.setFlcmc(spBzFlowConstant.getFlowName());
        List<SpcyFlowVo> spcyFlowList = spcyFlowMapper.flowJkList(onlyCurrentUser,user,ylqxFlowVo);

        Map<String, Long> bzlcFlowVo = new HashMap<>();
        if (CollectionUtils.isNotEmpty(spcyFlowList)){
            bzlcFlowVo = spcyFlowList.stream().collect(Collectors.groupingBy(
                    SpcyFlowVo::getFhjmc, Collectors.counting()
            ));
        }

        List<NodeTjVo> tjMap = bzlcFlowVo.entrySet().stream().map(e -> new NodeTjVo(e.getKey(), e.getValue())).collect(Collectors.toList());
        resultMap.put("bzlcNodeTj",tjMap);

        return resultMap;
    }

    /**
     * 专家流程 - 我的待办
     */
    public Map mySpcyZjFlowDb(boolean onlyCurrentUser,CurrentUserVo user,String fywflcode){
        Map resultMap = new HashMap();

        SpcyFlowVo ylqxFlowVo = new SpcyFlowVo();
        ylqxFlowVo.setFywflcode(fywflcode);
        ylqxFlowVo.setFblzt(SpcyConstant.BLZT_DB);
        ylqxFlowVo.setFlcmc(spcyZjFlowConstant.getFlowName());
        List<SpcyFlowVo> spcyFlowList = spcyFlowMapper.flowJkList(onlyCurrentUser,user,ylqxFlowVo);

        Map<String, Long> zjFlowVo = new HashMap<>();
        if (CollectionUtils.isNotEmpty(spcyFlowList)){
            zjFlowVo = spcyFlowList.stream().collect(Collectors.groupingBy(
                    SpcyFlowVo::getFhjmc, Collectors.counting()
            ));
        }

        List<NodeTjVo> tjMap = zjFlowVo.entrySet().stream().map(e -> new NodeTjVo(e.getKey(), e.getValue())).collect(Collectors.toList());
        resultMap.put("zjFlowNodeTj",tjMap);

        return resultMap;
    }

    /**
     * 整改流程 - 我的待办
     */
    public Map mySpcyZgFlowDb(boolean onlyCurrentUser,CurrentUserVo user,String fywflcode){
        Map resultMap = new HashMap();

        SpcyFlowVo ylqxFlowVo = new SpcyFlowVo();
        ylqxFlowVo.setFywflcode(fywflcode);
        ylqxFlowVo.setFblzt(SpcyConstant.BLZT_DB);
        ylqxFlowVo.setFlcmc(SpZgqrFlowConstant.FLOW_NAME);
        List<SpcyFlowVo> spcyFlowList = spcyFlowMapper.flowJkList(onlyCurrentUser,user,ylqxFlowVo);

        Map<String, Long> zjFlowVo = new HashMap<>();
        if (CollectionUtils.isNotEmpty(spcyFlowList)){
            zjFlowVo = spcyFlowList.stream().collect(Collectors.groupingBy(
                    SpcyFlowVo::getFhjmc, Collectors.counting()
            ));
        }

        List<NodeTjVo> tjMap = zjFlowVo.entrySet().stream().map(e -> new NodeTjVo(e.getKey(), e.getValue())).collect(Collectors.toList());
        resultMap.put("zgFlowNodeTj",tjMap);

        return resultMap;
    }

    /**
     * 技术审查报告 - 我的待办
     */
    public Map mySpcyJsscbgFlowDb(boolean onlyCurrentUser,CurrentUserVo user){
        Map resultMap = new HashMap();

        SpcyFlowVo flowVo = new SpcyFlowVo();
        flowVo.setFblzt(SpcyConstant.BLZT_DB);
        flowVo.setFlcmc(jsscbgFlowConstant.getFlowName());
        List<SpcyFlowVo> spcyFlowList = spcyFlowMapper.flowJkList(onlyCurrentUser,user,flowVo);

        Map<String, Long> zjFlowVo = new HashMap<>();
        if (CollectionUtils.isNotEmpty(spcyFlowList)){
            zjFlowVo = spcyFlowList.stream().collect(Collectors.groupingBy(
                    SpcyFlowVo::getFhjmc, Collectors.counting()
            ));
        }

        List<NodeTjVo> tjMap = zjFlowVo.entrySet().stream().map(e -> new NodeTjVo(e.getKey(), e.getValue())).collect(Collectors.toList());
        resultMap.put("jsscbgFlowNodeTj",tjMap);

        return resultMap;
    }

    /**
     * 企业申请申请 - 我的待办
     */
    public Map mySpcyQycjsqFlowDb(boolean onlyCurrentUser,CurrentUserVo user){
        Map resultMap = new HashMap();

        SpcyFlowVo flowVo = new SpcyFlowVo();
        flowVo.setFblzt(SpcyConstant.BLZT_DB);
        flowVo.setFlcmc(QycjsqFlowConstant.FLOW_NAME);
        List<SpcyFlowVo> spcyFlowList = spcyFlowMapper.flowJkList(onlyCurrentUser,user,flowVo);

        Map<String, Long> zjFlowVo = new HashMap<>();
        if (CollectionUtils.isNotEmpty(spcyFlowList)){
            zjFlowVo = spcyFlowList.stream().collect(Collectors.groupingBy(
                    SpcyFlowVo::getFhjmc, Collectors.counting()
            ));
        }

        List<NodeTjVo> tjMap = zjFlowVo.entrySet().stream().map(e -> new NodeTjVo(e.getKey(), e.getValue())).collect(Collectors.toList());
        resultMap.put("nodeTj",tjMap);

        return resultMap;
    }

    /**
     * 质量体系文件 - 流程 我的待办
     */
    public Map myZltxwjFlowDb(boolean onlyCurrentUser,CurrentUserVo user){
        Map resultMap = new HashMap();

        Page<ZltxwjFlowListVo> page = new Page<>(1, 100);
        ZltxwjFlowListVo flowVo = new ZltxwjFlowListVo();
        flowVo.setFblzt(SpcyConstant.BLZT_DB);
        flowVo.setFlcmc(zltxwjFlowConstant.getFlowName());
        IPage<ZltxwjFlowListVo> flowList = spcyZltxwjFlowMapper.flowJkPage(page,onlyCurrentUser,user,flowVo);

        Map<String, Long> zjFlowVo = new HashMap<>();
        if (CollectionUtils.isNotEmpty(flowList.getRecords())){
            zjFlowVo = flowList.getRecords().stream().collect(Collectors.groupingBy(
                    ZltxwjFlowListVo::getFhjmc, Collectors.counting()
            ));
        }

        List<NodeTjVo> tjMap = zjFlowVo.entrySet().stream().map(e -> new NodeTjVo(e.getKey(), e.getValue())).collect(Collectors.toList());
        resultMap.put("zltxwjFlowNodeTj",tjMap);

        return resultMap;
    }

    /**
     * 日常考评 - 我的待办
     */
    public Map myRckpWithDb(Page<SpcyFlowVo> page,boolean onlyCurrentUser,CurrentUserVo user){
        Map map = new HashMap();

        SpcyFlowVo rckpFlowVo = new SpcyFlowVo();
        rckpFlowVo.setFblzt(SpcyConstant.BLZT_DB);
        rckpFlowVo.setFlcmc(SpcyConstant.RCKP_FLOW_NAME);
        IPage<SpcyFlowVo> rckpFlowList = spcyFlowMapper.flowJkPage(page,onlyCurrentUser,user,rckpFlowVo,new OrderItemVo());

//        map.put("dbList",rckpFlowList.getRecords()); // 待办列表

        Map<String, Long> rckpFlowVoMap = new HashMap<>();
        if (CollectionUtils.isNotEmpty(rckpFlowList.getRecords())){
            rckpFlowVoMap = rckpFlowList.getRecords().stream().collect(Collectors.groupingBy(
                    SpcyFlowVo::getFhjmc, Collectors.counting()
            ));
        }
        List<NodeTjVo> tjMap = rckpFlowVoMap.entrySet().stream().map(e -> new NodeTjVo(e.getKey(), e.getValue())).collect(Collectors.toList());
        map.put("nodeTj",tjMap);

        return map;
    }

    /**
     * 预备检查考评 - 我的待办
     */
    public Map myYbjcyKpWithDb(Integer pageNo,Integer pageSize,boolean onlyCurrentUser,CurrentUserVo user){
        Map map = new HashMap();
        YbjcyFlowVo ybjcyFlowVo = new YbjcyFlowVo();
        ybjcyFlowVo.setFblzt(SpcyConstant.BLZT_DB);
        Page<YbjcyFlowVo> ybPage = new Page<>(pageNo, pageSize);
        IPage<YbjcyFlowVo> ybjcyFlowList = spcyKpYbjcyMapper.flowJobPage(ybPage,onlyCurrentUser,user,ybjcyFlowVo);

//        map.put("dbList",ybjcyFlowList.getRecords()); // 待办数据

        Map<String, Long> ybjcyFlowVoMap = new HashMap<>();
        if (CollectionUtils.isNotEmpty(ybjcyFlowList.getRecords())){
            ybjcyFlowVoMap = ybjcyFlowList.getRecords().stream().collect(Collectors.groupingBy(
                    YbjcyFlowVo::getFhjmc, Collectors.counting()
            ));
        }
        List<NodeTjVo> tjMap = ybjcyFlowVoMap.entrySet().stream().map(e -> new NodeTjVo(e.getKey(), e.getValue())).collect(Collectors.toList());

        map.put("nodeTj",tjMap);

        return map;
    }

    /**
     * 年度考评 - 药品注册 - 我的待办
     */
    public Map myNdkpByYpzcDb(Page<NdkpFlowVo> page2, boolean onlyCurrentUser, CurrentUserVo user){
        Map resultMap = new HashMap();
        Map map = new HashMap();

        NdkpFlowVo ypzcNdkpFlowVo = new NdkpFlowVo();
        ypzcNdkpFlowVo.setFywflcode(SpcyConstant.YWFL_CODE_YPZC);
        ypzcNdkpFlowVo.setFblzt(SpcyConstant.BLZT_DB);
        IPage<NdkpFlowVo> ypzcNdkpFlowList = spcyKpNdkpBasicMapper.flowJkPage(page2,onlyCurrentUser,user,ypzcNdkpFlowVo);

//        map.put("dbList",ypzcNdkpFlowList.getRecords()); // 待办数据

        Map<String, Long> ypzcNdkpFlowVoMap = new HashMap<>();
        if (CollectionUtils.isNotEmpty(ypzcNdkpFlowList.getRecords())){
            ypzcNdkpFlowVoMap = ypzcNdkpFlowList.getRecords().stream().collect(Collectors.groupingBy(
                    NdkpFlowVo::getFhjmc, Collectors.counting()
            ));
        }
        List<NodeTjVo> tjMap = ypzcNdkpFlowVoMap.entrySet().stream().map(e -> new NodeTjVo(e.getKey(), e.getValue())).collect(Collectors.toList());
        map.put("nodeTj",tjMap);

        resultMap.put("ypzc",map);
        return resultMap;
    }

    /**
     * 年度考评 - 药品生产 - 我的待办
     */
    public Map myNdkpByYpscDb(Page<NdkpFlowVo> page2,boolean onlyCurrentUser,CurrentUserVo user){
        Map resultMap = new HashMap();
        Map map = new HashMap();

        NdkpFlowVo ypscNdkpFlowVo = new NdkpFlowVo();
        ypscNdkpFlowVo.setFywflcode(SpcyConstant.YWFL_CODE_YPSC);
        ypscNdkpFlowVo.setFblzt(SpcyConstant.BLZT_DB);
        IPage<NdkpFlowVo> ypscNdkpFlowList = spcyKpNdkpBasicMapper.flowJkPage(page2,onlyCurrentUser,user,ypscNdkpFlowVo);

//        map.put("dbList",ypscNdkpFlowList.getRecords()); // 待办数据

        Map<String, Long> ypscNdkpFlowVoMap = new HashMap<>();
        if (CollectionUtils.isNotEmpty(ypscNdkpFlowList.getRecords())){
            ypscNdkpFlowVoMap = ypscNdkpFlowList.getRecords().stream().collect(Collectors.groupingBy(
                    NdkpFlowVo::getFhjmc, Collectors.counting()
            ));
        }
        List<NodeTjVo> tjMap = ypscNdkpFlowVoMap.entrySet().stream().map(e -> new NodeTjVo(e.getKey(), e.getValue())).collect(Collectors.toList());

        map.put("nodeTj",tjMap);

        resultMap.put("ypsc",map);
        return resultMap;
    }

    /**
     * 年度考评 - 药品流通 - 我的待办
     */
    public Map myNdkpByYpltDb(Page<NdkpFlowVo> page2,boolean onlyCurrentUser,CurrentUserVo user){
        Map resultMap = new HashMap();
        Map map = new HashMap();

        NdkpFlowVo ypltNdkpFlowVo = new NdkpFlowVo();
        ypltNdkpFlowVo.setFywflcode(SpcyConstant.YWFL_CODE_YPJY);
        ypltNdkpFlowVo.setFblzt(SpcyConstant.BLZT_DB);
        IPage<NdkpFlowVo> ypltNdkpFlowList = spcyKpNdkpBasicMapper.flowJkPage(page2,onlyCurrentUser,user,ypltNdkpFlowVo);

//        map.put("dbList",ypltNdkpFlowList.getRecords()); // 待办数据

        Map<String, Long> ypltNdkpFlowVoMap = new HashMap<>();
        if (CollectionUtils.isNotEmpty(ypltNdkpFlowList.getRecords())){
            ypltNdkpFlowVoMap = ypltNdkpFlowList.getRecords().stream().collect(Collectors.groupingBy(
                    NdkpFlowVo::getFhjmc, Collectors.counting()
            ));
        }
        List<NodeTjVo> tjMap = ypltNdkpFlowVoMap.entrySet().stream().map(e -> new NodeTjVo(e.getKey(), e.getValue())).collect(Collectors.toList());
        map.put("nodeTj",tjMap);

        resultMap.put("yplt",map);
        return resultMap;
    }

    /**
     * 年度考评 - 医疗器械 - 我的待办
     */
    public Map myNdkpByYlqxDb(Page<NdkpFlowVo> page2,boolean onlyCurrentUser,CurrentUserVo user){
        Map resultMap = new HashMap();
        Map map = new HashMap();

        NdkpFlowVo ylqxNdkpFlowVo = new NdkpFlowVo();
        ylqxNdkpFlowVo.setFywflcode(SpcyConstant.YWFL_CODE_YLQX);
        ylqxNdkpFlowVo.setFblzt(SpcyConstant.BLZT_DB);
        IPage<NdkpFlowVo> ylqxNdkpFlowList = spcyKpNdkpBasicMapper.flowJkPage(page2,onlyCurrentUser,user,ylqxNdkpFlowVo);

//        map.put("dbList",ylqxNdkpFlowList.getRecords()); // 待办数据

        Map<String, Long> ylqxNdkpFlowVoMap = new HashMap<>();
        if (CollectionUtils.isNotEmpty(ylqxNdkpFlowList.getRecords())){
            ylqxNdkpFlowVoMap = ylqxNdkpFlowList.getRecords().stream().collect(Collectors.groupingBy(
                    NdkpFlowVo::getFhjmc, Collectors.counting()
            ));
        }
        List<NodeTjVo> tjMap = ylqxNdkpFlowVoMap.entrySet().stream().map(e -> new NodeTjVo(e.getKey(), e.getValue())).collect(Collectors.toList());
        map.put("nodeTj",tjMap);

        resultMap.put("ylqx",map);
        return resultMap;
    }

    /**
     * 年度考评 - 化妆品 - 我的待办
     */
    public Map myNdkpByHzpDb(Page<NdkpFlowVo> page2,boolean onlyCurrentUser,CurrentUserVo user){
        Map resultMap = new HashMap();
        Map map = new HashMap();

        NdkpFlowVo hzpNdkpFlowVo = new NdkpFlowVo();
        hzpNdkpFlowVo.setFywflcode(SpcyConstant.YWFL_CODE_HZP);
        hzpNdkpFlowVo.setFblzt(SpcyConstant.BLZT_DB);
        IPage<NdkpFlowVo> hzpNdkpFlowList = spcyKpNdkpBasicMapper.flowJkPage(page2,onlyCurrentUser,user,hzpNdkpFlowVo);

//        map.put("dbList",hzpNdkpFlowList.getRecords()); // 待办数据

        Map<String, Long> hzpNdkpFlowVoMap = new HashMap<>();
        if (CollectionUtils.isNotEmpty(hzpNdkpFlowList.getRecords())){
            hzpNdkpFlowVoMap = hzpNdkpFlowList.getRecords().stream().collect(Collectors.groupingBy(
                    NdkpFlowVo::getFhjmc, Collectors.counting()
            ));
        }
        List<NodeTjVo> tjMap = hzpNdkpFlowVoMap.entrySet().stream().map(e -> new NodeTjVo(e.getKey(), e.getValue())).collect(Collectors.toList());
        map.put("nodeTj",tjMap);

        resultMap.put("hzp",map);
        return resultMap;
    }
}
